<template>
  <div class="mb20">
    <jxf-titletip title="转出结算明细 (已通过)" :hasRefresh="false" :hasGoBack="true"
                  @goBack="$emit('update:isShowDetail', false)"></jxf-titletip>
    <jxf-datalist class="mt20" :info="settleInfoList" :lineNum="2"></jxf-datalist>
    <el-card class="jxf-table-card mt20">
      <div slot="header">
        <span>数据列表</span>
        <div>
          <el-button type="primary" @click="exportData" :loading="isSuccess">导出</el-button>
        </div>
      </div>
      <jxf-table :table="tableInfo">
        <template slot="rate" slot-scope="scope">
          <span>{{scope.row.rate !== "" && scope.row.rate !== null ? parseInt(scope.row.rate * 10000)/100 + "%" : ""}}</span>
        </template>
      </jxf-table>
    </el-card>
  </div>
</template>

<script>
  import formatDate from '@/assets/js/formatDate'

  export default {
    name: "AdvanceTransferSettlementDetail",
    props: {
      isShowDetail: {
        type: Boolean,
        default: false
      }
    },
    data() {
      return {
        isSuccess: false,
        tableInfo: {},
        settleInfoList:[]
      }
    },
    methods: {
      // 列表初始化
      init() {
        this.tableInfo = {
          headerStyle: {background: '#f9f9f9'},
          border: true,
          loading: true,
          tr: [
            {
              id: '1',
              width: '120',
              label: '提前转出单号（提前提现）',
              prop: 'applyNo',
            },
            {
              id: '2',
              label: '订单编号',
              width: '110',
              prop: 'orderNo'
            },
            {
              id: '3',
              width: '160',
              label: '订单完结时间',
              prop: 'payTime'
            },
            {
              id: '4',
              width: '160',
              label: '申请转出时间',
              prop: 'applyTime'
            },
            {
              id: '5',
              minWidth: '120',
              label: '订单结算金额',
              prop: 'amount'
            },
            {
              id: '6',
              label: '转出金额',
              prop: 'actualAmount'
            },
            {
              id: '7',
              label: '提前月份',
              prop: 'count'
            },
            {
              id: '8',
              label: '计算费率',
              show: "template",
              prop: 'rate'
            },
            {
              id: '9',
              minWidth: '140',
              label: '提前转出手续费',
              prop: 'facAmount'
            },
            {
              id: '10',
              label: '结算时间',
              width: '160',
              prop: 'settleTime'
            }],
          data: []
        }
      },
      getInfo(row){
        this.getSettlementRecordDetail(row)
        this.getApplyOrderList(row)
      },
      getSettlementRecordDetail(row) {
        ajax.get(apis.factory.getSettlementRecordDetail, {applyId: row.id})
          .then(res => {
            if (res.success === true) {
              if (res.data !== [] && res.data !== null) {
                this.status = res.data.status
                this.settleInfoList = this.formatSettleData(res.data)
              } else {
                this.tableInfo.data = []
              }
              this.tableInfo.loading = false
            }
          })
      },
      getApplyOrderList(row) {
        ajax.get(apis.factory.getApplyOrderList, {applyId: row.id})
          .then(res => {
            if (res.success === true) {
              if (res.data !== [] && res.data !== null) {
                this.tableInfo.data = this.formatshowData(res.data)
              } else {
                this.tableInfo.data = []
              }
              this.tableInfo.loading = false
            }
          })
      },
      // 数据处理
      formatSettleData(item) {
        return [{
          label: "供应商企业名称",
          value: item.enterpriseName === null ? "": item.enterpriseName
        }, {
          label: "审核人",
          value: item.auditorName === null ? "": item.auditorName
        }, {
          label: "提前转出总额",
          value: item.amount
        }, {
          label: "审核时间",
          value: item.auditTime !== null && item.auditTime !== "" ? formatDate.timeFormat(item.auditTime) : ""
        }, {
          label: "提前转出手续费",
          value: item.facAmount
        }, {
          label: "结算时间",
          value: item.auditTime !== null && item.auditTime !== "" ? formatDate.timeFormat(item.auditTime) : ""
        }, {
          label: "结算金额",
          value: item.actualAmount
        }, {
          label: "审核备注",
          value: item.reason
        }]
      },
      // 数据处理
      formatshowData(info) {
        return info.map(item => {
          return {
            applyNo: item.applyNo,
            orderNo: item.orderNo,
            payTime: item.payTime !== null && item.payTime !== "" ? formatDate.timeFormat(item.payTime) : "",
            applyTime: item.applyTime !== null && item.applyTime !== "" ? formatDate.timeFormat(item.applyTime) : "",
            amount: item.amount,
            count: item.count,
            rate: item.rate,
            facAmount: item.facAmount,
            actualAmount: item.actualAmount,
            settleTime: item.settleTime !== null && item.settleTime !== "" ? formatDate.timeFormat(item.settleTime) : ""
          }
        })
      },
      exportData(){
        this.isSuccess = true;
        ajax.export(apis.factory.exportApplyOrderList, {applyId:this.auditInfo.id})
          .then(res => {
            this.isSuccess = false
          })
      }
    },
    created() {
      this.init()
    }
  }
</script>

<style lang="scss" scoped>

</style>
